from rest_framework.serializers import ListField, Serializer, ModelSerializer, CharField
from certificate_manager.models import Level

class LevelSerializer(ModelSerializer):
        
        class Meta:
            model = Level
            fields = ['pk', 'name', 'nested_level', 'cate']

        def to_representation(self, level):
            return {
                'pk': level.pk,
                'name': str(level)
            }


class SubLevelSerializer(ModelSerializer):
        class Meta:
            model = Level
            fields = ['pk', 'name']


class NestedLevelSerializer(Serializer):
        nested_level = SubLevelSerializer(many=True, required=True)
        name = CharField(max_length=10)

        class Meta:
            fields = ['pk', 'name', 'nested_level']
